Skip to content

Conversation

@BaldPRs
Copy link
Contributor

@BaldPRs BaldPRs commented Jan 3, 2026

Problem:

TimeUntilBreak is awkward for programmatic use. It returns a formatted string, which is useful for logging but requires parsing to use in logic. To retrieve the MS until an antiban sleep or break you have to use something similar to the example code which is difficult to read, and mentioned nowhere in the docs.

Suggestion:

Add two helper functions that return the raw milliseconds until the next scheduled break/sleep (if one exists):
MsUntilBreak(): Double
MsUntilSleep(): Double

Example Before:

{$I WaspLib/osrs.simba}

begin
  if ((Length(Antiban.Breaks) > 0) and (Antiban.Breaks[0].Next - GetTimeRunning() < Random(140, 240) * ONE_SECOND)) or
     ((Length(Antiban.Sleeps) > 0) and (Antiban.Sleeps[0].Next - GetTimeRunning() < Random(140, 240) * ONE_SECOND)) then
    WriteLn('Break coming soon!');
end;

Example After:

{$I WaspLib/osrs.simba}

begin
  if (Antiban.MsUntilBreak() < Random(140, 240) * ONE_SECOND) or
     (Antiban.MsUntilSleep() < Random(140, 240) * ONE_SECOND) then
    WriteLn('Break coming soon!');
end;

Use Case

A Scripter wants to clean up or perform specific actions before a break interrupts execution. This helper now allows the scripter to perform a simple MS comparison against the upcoming break/sleep.

@BaldPRs BaldPRs changed the title Add MsUntilBreak, and MsUntilSleep AntiBan helpers feat: Add MsUntilBreak, and MsUntilSleep AntiBan helpers Jan 3, 2026
@BaldPRs BaldPRs changed the title feat: Add MsUntilBreak, and MsUntilSleep AntiBan helpers feat(Antiban): Add MsUntilBreak, and MsUntilSleep AntiBan helpers Jan 3, 2026
@Torwent
Copy link
Collaborator

Torwent commented Jan 7, 2026

If you give me a good use case I'll merge it 😉

The use case you gave is not a good one! It already has a solution:

TAntiban = record  
  //...
  //...
  OnStartTask,  OnFinishTask:  procedure(task: PAntibanTask) of object;
  OnStartBreak, OnFinishBreak: procedure(task: PBreakTask)   of object;
  OnStartSleep, OnFinishSleep: procedure(task: PSleepTask)   of object;
  //...
  //...
end;

And this solution is better because what you are suggesting for the scripter to know there's a break coming is misleading.
A break can be due but it will never happen unless the scripter calls Antiban.DoAntiban().

The built-in approach however runs every time at the start of the task, break or sleep when you are actually going to do it for sure and as a bonus you also have OnFinish callbacks to restore your script properly if you need.

TimeUntilBreak and TimeUntilSleep is awkward to use programatically because they are not meant to be used programatically. They are meant to show a string to users. What you want is the OnStart callbacks

@phron3sis
Copy link

phron3sis commented Jan 12, 2026

this is how i check if a break, task or sleep would be called if i called Antiban.Do

var
  i: Int32;
  activeTasks: PAntibanTaskArray;
begin
  if Self.DoingAntiban then
    Exit(False);

  activeTasks := Self.GetActiveTasks();
  for i := 0 to High(activeTasks) do
    if activeTasks[i]^.Countdown.Remaining = 0 then
      Exit(True);

  Result := False;
end;


function TAntiban.BreakDue(): Boolean;
var
  i: Int32;
  t: UInt64;
begin
  if Self.DoingAntiban then
    Exit(False);

  t := GetTimeRunning();
  for i := 0 to High(Self.Breaks) do
    if t > Self.Breaks[i].Next then
      Exit(True);

  Result := False;
end;


function TAntiban.SleepDue(): Boolean;
var
  i: Int32;
  t: UInt64;
begin
  if Self.DoingAntiban then
    Exit(False);

  t := GetTimeRunning();
  for i := 0 to High(Self.Sleeps) do
    if t > Self.Sleeps[i].Next then
      Exit(True);

  Result := False;
end;

I use that to set my state, and then call the specific antiban so my script state updates first.

@BaldPRs
Copy link
Contributor Author

BaldPRs commented Jan 12, 2026

@Torwent @phron3sis
I'm good to close this out. The existing solutions make sense to me but were missing from the docs and I hadn't checked what was available to me within Antiban.

I appreciate the feedback, I may do a PR to add docstrings to these and clarify some of this for those who come after me :)

Thx!

@BaldPRs BaldPRs closed this Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants